package Image;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * description:缩略图
 * author:zcx
 * lenovo
 * 时间：2022.01.24.21.20
 */
public class Ex6 {
    public static void main(String[] args) throws IOException {
        //jd src 800_800
        var src = ImageIO.read(new File("pok2.png"));
        var sw = src.getWidth();
        var sh = src.getHeight();


        //350_350 指定宽高
        var dw = 50;
        var dh = 50;
        var dst = new BufferedImage(dw, dh, 1);
        var g = dst.createGraphics();
        //设置线条和文件的，抗锯齿（平滑）
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);

        g.drawImage(src, 0, 0, dw, dh, null);

        g.dispose();
        //保存图像文件
        try {
            ImageIO.write(dst, "jpg", new File("i_50_50.jpg"));
        } catch (Exception e) {
            e.printStackTrace();
        }

        //打开图像文件
        try {
            Runtime.getRuntime().exec("cmd /k start i_50_50.jpg");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
